/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 let {list,ListNode}=require('./lianbiao');
 var swapPairs = function(head) {
    if(!head || !head.next){
        return head;
    }
    let newhead = new ListNode();
    newhead.next=head;
    let node = newhead;
    while(head!=null && head.next!=null){
        let p=head.next;
        head.next=p.next;
        p.next=head;
        node.next=p;
        node=head;
        head=head.next;
    };
    return newhead.next;
 }


 let arr=[1,2,3,5,8,9,10];
 let head=list(arr);
 console.log(swapPairs(head));